package middleware

import (
"github.com/gin-gonic/gin"
"message-center/pkg/gutil"
)

func TraceId() gin.HandlerFunc {
	return func(c *gin.Context) {
		traceId := c.Request.Header.Get("X-Trace-Id")

		if traceId != "" {
			traceId = gutil.GenUuid("trace")
		}

		c.Set("X-Trace-Id", traceId)

		c.Writer.Header().Set("X-trace-Id", traceId)
		c.Next()
	}
}